﻿using MMITWeb.Controllers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using MMITWeb.Infrastructure.Abstract;
using MMITWeb.Models;
using System.Web.Mvc;
using Moq;
using MMITDomain.Abstract;
using MMITDomain.Entities;

namespace MMITUnitTests
{
    
    
    /// <summary>
    ///This is a test class for UserAccountControllerTest and is intended
    ///to contain all UserAccountControllerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class UserAccountControllerTest
    {


        private TestContext testContextInstance;
        private Mock<ICustomerRepository> MockCustomerRep;
        private Mock<IIdentificationTypeRepository> MockIdentificationRep;
        private Mock<ICountryRepository> MockCountryRep;
        private Mock<IAuthProvider> MockAuthProvider;
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
        [TestInitialize]
        public void Initialize(){
            //Arrange
            MockCustomerRep = new Mock<ICustomerRepository>();
            MockIdentificationRep = new Mock<IIdentificationTypeRepository>();
            MockCountryRep = new Mock<ICountryRepository>();
            MockAuthProvider = new Mock<IAuthProvider>();

            MockAuthProvider.Setup(m => m.Authenticate("lashman3", "faraday")).Returns(true);
        }
        /// <summary>
        ///A test for Register
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void RegisterTest()
        {
            //Arrange

            //Arrange
            //MockAuthProvider.Setup(m => m.Register("superman", "password", "super@gmail.com", "Super", "Man", "Forever", "08098765476", 
             //   152, 2, "A123456", out output));

           // MockCustomerRep.Setup(c => c.Customers).Returns(new Customer[]{new Customer{ },new Customer{}
           // });

            //UserAccountController target = new UserAccountController(MockAuthProvider.Object, MockCountryRep.Object, 
            //    MockIdentificationRep.Object, MockCustomerRep.Object); 

            //RegisterViewModel model = new RegisterViewModel();
            //model.UserName = "superman";
            //model.Password = "password";
            //model.Email = "super@gmail.com";
            //model.Firstname = "Super";
            //model.Middlename = "Man";
            //model.Lastname = "Forever";
            //model.Mobile ="08098765476";
            //model.IdentificationNumber = "A123456";
            
            //var actual = target.Register(model,152,2);
            //Assert.IsInstanceOfType(actual, typeof(ViewResult));
            //Assert.AreEqual("/Home/Index", actual.Url);
        }

        /// <summary>
        ///A test for LogOn
        ///</summary>
        // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,
        // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,
        // whether you are testing a page, web service, or a WCF service.
        [TestMethod()]
        public void LogOnTest()
        {
            //Arrange

            ////Arrange - Create a Controller...
            //UserAccountController target = new UserAccountController(MockAuthProvider.Object, MockCountryRep.Object,
            //                                MockIdentificationRep.Object, MockCustomerRep.Object); 
            
            //LogOnViewModel model = new LogOnViewModel();
            //model.Username = "lashman3";
            //model.Password = "faraday";

            ////Action - 
            //var result = (RedirectResult)target.LogOn(model,"/Home/Index");

            //Assert.AreEqual("/Home/Index", result.Url);
            
        }
    }
}
